package com.wtb.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wtb.domain.Config;
import com.wtb.thread.MailSendThread;
import com.wtb.utils.mail.MailSenderInfo;
import com.wtb.utils.mail.SimpleMailSender;
/**
 * 邮件发送工具
 * @author Administrator
 *
 */
public class MailUtils {
	private static final Log log = LogFactory.getLog(MailSendThread.class);
	public static void sendMail(String message){
		SimpleMailSender sms = new SimpleMailSender();
		MailSenderInfo mailInfo = new MailSenderInfo();
		try {
			mailInfo.setMailServerHost(Config.MAIL_SERVER_HOST);
			mailInfo.setMailServerPort("25");
			mailInfo.setValidate(true);
			mailInfo.setUserName(Config.MAIL_USER_NAME);
			mailInfo.setPassword(Config.MAIL_PASSWORD);
			mailInfo.setFromAddress(Config.MAIL_FROM);
			mailInfo.setSubject("微同步异常");
			for (int i = 0; i < Config.MAIL_RECEIVERS.length; i++) {
				log.info("异常邮件正在准备发送。。。。。。。。。。。。。。。。。");
				mailInfo.setToAddress(Config.MAIL_RECEIVERS[i]);
				mailInfo.setContent(message);
				sms.sendTextMail(mailInfo);
				log.info("异常邮件已发送给-----"+Config.MAIL_RECEIVERS[i]);
			}
		} catch (Exception e) {
			log.error("发送异常邮件失败：", e);
		}
	}
}
